#ifndef __PLATFORM_LIB_XML_H__
#define __PLATFORM_LIB_XML_H__
#ifdef __cplusplus
extern "C"
{
#endif

#include "pf_common.h" 

/******************************************************************************************************/

typedef struct pf_xml pf_xml_t;

typedef struct pf_xml_element pf_xml_element_t;

typedef struct pf_xml_text pf_xml_text_t;

typedef struct pf_xml_attribute pf_xml_attribute_t;

typedef struct pf_xml_clear pf_xml_clear_t;

/*********************************************************************************************
Function Name:  pf_xml_create
Description  :  Create a xml
Inputs       :
Outputs      :  return value            :   The pointer of created xml
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_t* pf_xml_create(const char* root);

/*********************************************************************************************
Function Name:  pf_xml_destroy
Description  :  Destroy a xml
Inputs       :
Outputs      :  return value            :   0
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern int pf_xml_destroy(pf_xml_t* xml);

/*********************************************************************************************
Function Name:  pf_xml_clearup
Description  :  clear a xml except the root and declare
Inputs       :
Outputs      :  return value            :   0
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern int pf_xml_clearup(pf_xml_t* xml);

/*********************************************************************************************
Function Name:  pf_xml_get_root
Description  :  Get the root element of the xml
Inputs       :
Outputs      :  return value            :   The pointer of root element
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_element_t* pf_xml_get_root(pf_xml_t* xml);

/*********************************************************************************************
Function Name:  pf_xml_attrib_get_name
Description  :  Get the attribute 's name
Inputs       :
Outputs      :  return value            :   The pointer of attrib name buf
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_attrib_get_name(pf_xml_attribute_t* attrib);

/*********************************************************************************************
Function Name:  pf_xml_attrib_get_value
Description  :  Get the attribute 's value
Inputs       :
Outputs      :  return value            :   The pointer of attrib value buf
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_attrib_get_value(pf_xml_attribute_t* attrib);

/*********************************************************************************************
Function Name:  pf_xml_elem_get_name
Description  :  Get the element 's name
Inputs       :
Outputs      :  return value            :   The pointer of element name buf
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_elem_get_name(pf_xml_element_t* element);

/*********************************************************************************************
Function Name:  pf_xml_elem_get_text
Description  :  Get the element 's text
Inputs       :
Outputs      :  return value            :   The pointer of element text buf
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_elem_get_text(pf_xml_element_t* element);

/*********************************************************************************************
Function Name:  pf_xml_init_declare
Description  :  Init the declare
Inputs       :
Outputs      :  return value            :   0 success, other fail
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern int pf_xml_init_declare(pf_xml_t* xml, 
                               const char* version, 
                               const char* encoding, 
                               const char* standalone);

/*********************************************************************************************
Function Name:  pf_xml_get_version
Description  :  Get declare 's version
Inputs       :
Outputs      :  return value            :   The pointer of declare 's version
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_get_version(pf_xml_t* xml);

/*********************************************************************************************
Function Name:  pf_xml_get_encoding
Description  :  Get declare 's encoding
Inputs       :
Outputs      :  return value            :   The pointer of declare 's encoding
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_get_encoding(pf_xml_t* xml);

/*********************************************************************************************
Function Name:  pf_xml_get_standalone
Description  :  Get declare 's standalone
Inputs       :
Outputs      :  return value            :   The pointer of declare 's standalone
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_get_standalone(pf_xml_t* xml);

/*********************************************************************************************
Function Name:  pf_xml_insert_element
Description  :  Insert a new element under the existed one
Inputs       :
Outputs      :  return value            :   The pointer of created new element
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_element_t* pf_xml_insert_element(pf_xml_element_t* element, const char* name);

/*********************************************************************************************
Function Name:  pf_xml_insert_text
Description  :  Insert the text by the element
Inputs       :
Outputs      :  return value            :   The pointer of created new text
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_text_t* pf_xml_insert_text(pf_xml_element_t* element, const char* value);

/*********************************************************************************************
Function Name:  pf_xml_insert_attribute
Description  :  Insert the attribute by the element
Inputs       :
Outputs      :  return value            :   The pointer of created new attribute
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_attribute_t* pf_xml_insert_attribute(pf_xml_element_t* element, 
                                                   const char* name, 
                                                   const char* value);

/*********************************************************************************************
Function Name:  pf_xml_insert_cdata
Description  :  Insert the cdata(clear) by the element
Inputs       :
Outputs      :  return value            :   The pointer of created new clear
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_clear_t* pf_xml_insert_cdata(pf_xml_element_t* entry, const char* name);

/*********************************************************************************************
Function Name:  pf_xml_parse
Description  :  Parse the xml string to the pf_xml object
Inputs       :
Outputs      :  return value            :   The pointer of parsed xml
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_t* pf_xml_parse(const char* xmlstr);

/*********************************************************************************************
Function Name:  pf_xml_dump
Description  :  dump the pf_xml object to the xml string, you must free the return string
Inputs       :
Outputs      :  return value            :   The pointer of xml string buf
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern char* pf_xml_dump(pf_xml_t* xml, int format);

/*********************************************************************************************
Function Name:  pf_xml_enum_elements
Description  :  Enum all elements by the element 
Inputs       :
Outputs      :  return value            :   The pointer of enum element
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_element_t* pf_xml_enum_elements(pf_xml_element_t* entry, int* idx);

/*********************************************************************************************
Function Name:  pf_xml_enum_attributes
Description  :  Enum all attributes by the element 
Inputs       :
Outputs      :  return value            :   The pointer of enum attribute
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_attribute_t* pf_xml_enum_attributes(pf_xml_element_t* entry, int* idx);

/*********************************************************************************************
Function Name:  pf_xml_find_element
Description  :  Find the first element by the path
Inputs       :
Outputs      :  return value            :   The pointer of finded element
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_element_t* pf_xml_find_element(pf_xml_element_t* head, const char* path);

/*********************************************************************************************
Function Name:  pf_xml_find_attribute
Description  :  Find the first attribute by attrib 's name
Inputs       :
Outputs      :  return value            :   The pointer of finded element
ErrorCodes   :
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
zhanggp                2011-06-23                    create
**********************************************************************************************/
extern pf_xml_attribute_t* pf_xml_find_attribute(pf_xml_element_t* entry, const char* attrib);

/******************************************************************************************************/

#ifdef __cplusplus
}
#endif
#endif /* #ifndef __PLATFORM_LIB_XML_H__ */

